<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<div id="sex">
			<label>
				男<input type="radio" name="sex" value="0" checked />
			</label>
			<label for="sex1">
				女
			</label>
			<input type="radio" name="sex" value="1" />
			<br />
			<br />
			<div>
				<button type="button" onclick="fn1()">获取性别</button><br /><br />
				<button type="button" onclick="fn2()">选中性别:女</button>
			</div>
			
		</div>
		<script>
			function fn1(){
			   var ipts=document.querySelectorAll("div#sex input[type='radio']");
			   console.log("ipts:",ipts);
			   var sexV;
			   if(ipts[0].checked){
				   sexV=ipts[0].value;
			   }else{
				   sexV=ipts[1].value;
			   }
			   console.log("sexV:",sexV,"你选中了 ",sexV=="0"?"小哥哥":"小姐姐")
		   }
		   function fn2(){
			   var ipts=document.querySelectorAll("div#sex input[type='radio']");
			   ipts[1].checked=true;
		   }
		</script>
	</body>
</html>
